package com.xing.morethread.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ThreadService {

    //@Async() //表示该方法异步执行
    @Async("pool2") //表示该方法异步执行,指定pool2
    public void run(){
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(
                    "线程池当前的名字："+Thread.currentThread().getName()
                            +"时间是："+new Date()+"执行了多线程任务"+i
            );
        }
    }

}
